package com.gateway.video.rtsp.server.channel;

import com.gateway.video.rtsp.server.codec.RtspServerCodec;
import com.gateway.video.rtsp.server.handler.RtspServerHandler;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

import java.io.IOException;

public class DefaultInitChannel implements InitChannel {
    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public void configuer(Channel channel) throws IOException {
        channel.config().setAutoRead(false);

        channel.pipeline().addLast(null, RtspServerCodec.class.getName(), new RtspServerCodec());
        channel.pipeline().addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
        channel.pipeline().addLast(applicationContext.getBeanProvider(RtspServerHandler.class).getObject());
    }
}
